package com.example.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.common.Result;
import com.example.dto.ArticleDeleteDTO;
import com.example.dto.ArticleDetailDTO;
import com.example.dto.ArticlePageDTO;
import com.example.dto.ArticlePublishDTO;
import com.example.service.ArticleService;
import com.example.vo.ArticleDetailVO;
import com.example.vo.ArticlePageVO;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 文章表 前端控制器
 * </p>
 *
 * @author wuyunbin
 * @since 2024-10-19
 */
@Slf4j
@RestController("adminArticleController")
@RequestMapping("/admin/article")
public class ArticleController {
    @Resource
    private ArticleService articleService;

    @PostMapping("/publish")
    public Result<Object> publish(@RequestBody ArticlePublishDTO articlePublishDTO){
        articleService.publish(articlePublishDTO);
        return Result.success();
    }

    @PostMapping("/list")
    public Result<IPage<ArticlePageVO>> list(@RequestBody ArticlePageDTO articlePageDTO){
        IPage<ArticlePageVO> page = articleService.getPage(articlePageDTO);
        return Result.success(page);
    }

    @PostMapping("/delete")
    public Result<Object> delete(@RequestBody ArticleDeleteDTO articleDeleteDTO){
        articleService.removeArticle(articleDeleteDTO);
        return Result.success();
    }

    @Operation(summary = "文章详情",description = "编辑文章时会显示数据用的接口")
    @PostMapping("/detail")
    public Result<ArticleDetailVO> detail(@RequestBody ArticleDetailDTO articleDetailDTO){
        ArticleDetailVO vo = articleService.detail(articleDetailDTO);
        return Result.success(vo);
    }

    @PostMapping("/update")
    public Result<Object> update(@RequestBody ArticlePublishDTO articlePublishDTO){
        articleService.updateArticle(articlePublishDTO);
        return Result.success();
    }





}
